package com.dianban.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 重试3次，每次间隔20秒。
 */
public class RequestTask implements Runnable {
    private Logger logger = LoggerFactory.getLogger(RequestTask.class);

    private String url;
    private String param;

    public RequestTask(String url, String param) {
        super();
        this.url = url;
        this.param = param;
    }

    @Override
    public void run() {
        int i = 1;
        int max = 3;
        while (true) {
            String result = HttpUtil.doPostByJson(url, param);
            logger.info("第" + i + "执行请求，返回结果：{}", result);
            i++;
            if (i > max) {
                break;
            }
            try {
                Thread.sleep(20 * 1000);//每次间隔30秒。
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
